/**
 * 项目相关类型定义
 */
import { BaseFileInfo, BaseExportConfig, BaseImportConfig, PaginationParams } from './base.types'

/**
 * 分辨率配置
 */
export interface Resolution {
  width: number
  height: number
}

/**
 * 项目数据接口
 */
export interface ProjectData {
  id?: string
  name: string
  description?: string
  resolution?: Resolution
  frameRate?: number
  duration?: number
  thumbnail?: string
  filePath?: string
  metadata?: ProjectMetadata
  createdAt?: string
  updatedAt?: string
  lastOpenedAt?: string
}

/**
 * 项目元数据
 */
export interface ProjectMetadata {
  version?: string
  author?: string
  tags?: string[]
  category?: string
  isTemplate?: boolean
  templateId?: string
  customProperties?: Record<string, any>
}

/**
 * 创建项目请求
 */
export interface CreateProjectRequest {
  name: string
  description?: string
  resolution?: Resolution
  frameRate?: number
  templateId?: string
  metadata?: Partial<ProjectMetadata>
}

/**
 * 更新项目请求
 */
export interface UpdateProjectRequest {
  id: string
  data: Partial<ProjectData>
}

/**
 * 项目查询参数
 */
export interface ProjectQueryParams extends PaginationParams {
  search?: string
  category?: string
  tags?: string[]
  author?: string
  dateRange?: {
    start: string
    end: string
  }
  isTemplate?: boolean
}

/**
 * 项目导出配置
 */
export interface ProjectExportConfig extends BaseExportConfig {
  format: 'mp4' | 'gif' | 'webm' | 'mov' | 'avi'
  resolution?: Resolution
  fps?: number
  startFrame?: number
  endFrame?: number
  includeAudio?: boolean
  watermark?: {
    enabled: boolean
    text?: string
    position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'center'
    opacity?: number
  }
}

/**
 * 项目导出请求
 */
export interface ProjectExportRequest {
  id: string
  config: ProjectExportConfig
  outputPath?: string
}

/**
 * 项目导入配置
 */
export interface ProjectImportConfig extends BaseImportConfig {
  preserveIds?: boolean
  updateExisting?: boolean
  importAssets?: boolean
  importSettings?: boolean
}

/**
 * 项目导入请求
 */
export interface ProjectImportRequest {
  filePath: string
  config?: ProjectImportConfig
}

/**
 * 项目模板
 */
export interface ProjectTemplate {
  id: string
  name: string
  description: string
  category: string
  thumbnail: string
  previewImages?: string[]
  tags: string[]
  author: string
  version: string
  resolution: Resolution
  frameRate: number
  duration: number
  complexity: 'beginner' | 'intermediate' | 'advanced'
  isPremium: boolean
  price?: number
  downloadCount: number
  rating: number
  reviewCount: number
  createdAt: string
  updatedAt: string
  projectData?: Partial<ProjectData>
}

/**
 * 项目统计信息
 */
export interface ProjectStats {
  totalProjects: number
  totalDuration: number
  averageDuration: number
  projectsByCategory: Record<string, number>
  projectsByMonth: Array<{
    month: string
    count: number
  }>
  recentActivity: Array<{
    projectId: string
    projectName: string
    action: 'created' | 'opened' | 'modified' | 'exported'
    timestamp: string
  }>
}

/**
 * 项目设置
 */
export interface ProjectSettings {
  autoSave: boolean
  autoSaveInterval: number
  backupEnabled: boolean
  backupInterval: number
  maxBackups: number
  defaultResolution: Resolution
  defaultFrameRate: number
  defaultDuration: number
  exportSettings: {
    defaultFormat: string
    defaultQuality: number
    includeWatermark: boolean
  }
}

/**
 * 项目历史记录
 */
export interface ProjectHistory {
  id: string
  projectId: string
  action: string
  description: string
  timestamp: string
  userId?: string
  changes?: Record<string, {
    before: any
    after: any
  }>
}

/**
 * 项目协作信息
 */
export interface ProjectCollaboration {
  projectId: string
  owner: string
  collaborators: Array<{
    userId: string
    username: string
    role: 'viewer' | 'editor' | 'admin'
    joinedAt: string
    lastActive: string
  }>
  permissions: {
    canEdit: boolean
    canExport: boolean
    canShare: boolean
    canDelete: boolean
  }
  shareSettings: {
    isPublic: boolean
    shareLink?: string
    password?: string
    expiresAt?: string
  }
}

/**
 * 项目备份信息
 */
export interface ProjectBackup {
  id: string
  projectId: string
  name: string
  description?: string
  filePath: string
  size: number
  createdAt: string
  isAutoBackup: boolean
  version: string
}

/**
 * 项目版本信息
 */
export interface ProjectVersion {
  id: string
  projectId: string
  version: string
  name: string
  description?: string
  changes: string[]
  createdAt: string
  createdBy: string
  isStable: boolean
  downloadUrl?: string
}

/**
 * 项目分析数据
 */
export interface ProjectAnalytics {
  projectId: string
  views: number
  downloads: number
  likes: number
  shares: number
  comments: number
  averageRating: number
  viewHistory: Array<{
    date: string
    views: number
  }>
  geographicData: Array<{
    country: string
    views: number
  }>
  deviceData: Array<{
    device: string
    views: number
  }>
}

/**
 * 项目搜索结果
 */
export interface ProjectSearchResult {
  projects: ProjectData[]
  total: number
  facets: {
    categories: Array<{ name: string; count: number }>
    tags: Array<{ name: string; count: number }>
    authors: Array<{ name: string; count: number }>
  }
  suggestions: string[]
}

/**
 * 项目操作权限
 */
export interface ProjectPermissions {
  canView: boolean
  canEdit: boolean
  canDelete: boolean
  canExport: boolean
  canShare: boolean
  canComment: boolean
  canRate: boolean
}

/**
 * 项目状态
 */
export type ProjectStatus = 'draft' | 'active' | 'archived' | 'deleted' | 'template'

/**
 * 项目排序选项
 */
export type ProjectSortOption = 
  | 'name-asc' 
  | 'name-desc' 
  | 'created-asc' 
  | 'created-desc' 
  | 'updated-asc' 
  | 'updated-desc' 
  | 'duration-asc' 
  | 'duration-desc'
  | 'size-asc'
  | 'size-desc'

/**
 * 项目过滤器
 */
export interface ProjectFilter {
  status?: ProjectStatus[]
  categories?: string[]
  tags?: string[]
  authors?: string[]
  dateRange?: {
    start: string
    end: string
  }
  durationRange?: {
    min: number
    max: number
  }
  hasTemplate?: boolean
  isPublic?: boolean
}
